//
//  SetPasswordApiModel.m
//  ZhuKuang
//
//  Created by jayce on 17/7/13.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "SetPasswordApiModel.h"
#import "HttpRequest.h"

@implementation SetPasswordApiModel

+ (void)setPassword:(NSDictionary *)postParams success:(ResponseBlock)response{
    
    //   字典转json
    NSString* str = @"";
    if ([DataCheck isValidDictionary:postParams]) {
        NSData* jsonData = [NSJSONSerialization dataWithJSONObject:postParams options:NSJSONWritingPrettyPrinted error:nil];
        str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    //拼接soap字符串
    NSString * soap = @"";
    soap = [NSString stringWithFormat:@"<funcName>%@</funcName>\n<content>%@</content>",SetPassword,str];
    [HttpRequest SOAPData:[CommClass getServerURL] SoapMthod:SetPassword soapBody:soap success:^(id responseObject) {
        NSInteger code =[[responseObject objectForKey:@"code"] integerValue];
        
        if (response) {
            response(responseObject);
        }
        if(code == 220) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [MBProgressHUD hideLoadViewWithView:kWindow];
                if ([DataCheck isValidString:responseObject[@"msg"]]) {
                    [MBProgressHUD postMessageWithText:[responseObject objectForKey:@"msg"] View:kWindow];
                }
            });
            return;
        }
        
    } failure:^(NSError *error) {
        [MBProgressHUD postMessageWithText:@"请求失败" View:kWindow];
        NSData *data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
        NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"服务器的错误原因：%@",str);
    }];

}
@end
